﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Maticsoft.DBUtility;//Please add references
namespace lcmyjobs.DAL
{
	/// <summary>
	/// 数据访问类:majors
	/// </summary>
	public partial class majors
	{
		public majors()
		{}
		#region  Method

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
		return DbHelperSQL.GetMaxID("majors_id", "majors"); 
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int majors_id)
		{
			int rowsAffected;
			SqlParameter[] parameters = {
					new SqlParameter("@majors_id", SqlDbType.Int,4)
};
			parameters[0].Value = majors_id;

			int result= DbHelperSQL.RunProcedure("majors_Exists",parameters,out rowsAffected);
			if(result==1)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		///  增加一条数据
		/// </summary>
		public int Add(lcmyjobs.Model.majors model)
		{
			int rowsAffected;
			SqlParameter[] parameters = {
					new SqlParameter("@majors_id", SqlDbType.Int,4),
					new SqlParameter("@major_name", SqlDbType.NVarChar,20)};
			parameters[0].Direction = ParameterDirection.Output;
			parameters[1].Value = model.major_name;

			DbHelperSQL.RunProcedure("majors_ADD",parameters,out rowsAffected);
			return (int)parameters[0].Value;
		}

		/// <summary>
		///  更新一条数据
		/// </summary>
		public bool Update(lcmyjobs.Model.majors model)
		{
			int rowsAffected=0;
			SqlParameter[] parameters = {
					new SqlParameter("@majors_id", SqlDbType.Int,4),
					new SqlParameter("@major_name", SqlDbType.NVarChar,20)};
			parameters[0].Value = model.majors_id;
			parameters[1].Value = model.major_name;

			DbHelperSQL.RunProcedure("majors_Update",parameters,out rowsAffected);
			if (rowsAffected > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int majors_id)
		{
			int rowsAffected=0;
			SqlParameter[] parameters = {
					new SqlParameter("@majors_id", SqlDbType.Int,4)
};
			parameters[0].Value = majors_id;

			DbHelperSQL.RunProcedure("majors_Delete",parameters,out rowsAffected);
			if (rowsAffected > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string majors_idlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from majors ");
			strSql.Append(" where majors_id in ("+majors_idlist + ")  ");
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public lcmyjobs.Model.majors GetModel(int majors_id)
		{
			SqlParameter[] parameters = {
					new SqlParameter("@majors_id", SqlDbType.Int,4)
};
			parameters[0].Value = majors_id;

			lcmyjobs.Model.majors model=new lcmyjobs.Model.majors();
			DataSet ds= DbHelperSQL.RunProcedure("majors_GetModel",parameters,"ds");
			if(ds.Tables[0].Rows.Count>0)
			{
				if(ds.Tables[0].Rows[0]["majors_id"]!=null && ds.Tables[0].Rows[0]["majors_id"].ToString()!="")
				{
					model.majors_id=int.Parse(ds.Tables[0].Rows[0]["majors_id"].ToString());
				}
				if(ds.Tables[0].Rows[0]["major_name"]!=null && ds.Tables[0].Rows[0]["major_name"].ToString()!="")
				{
					model.major_name=ds.Tables[0].Rows[0]["major_name"].ToString();
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select majors_id,major_name ");
			strSql.Append(" FROM majors ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ");
			if(Top>0)
			{
				strSql.Append(" top "+Top.ToString());
			}
			strSql.Append(" majors_id,major_name ");
			strSql.Append(" FROM majors ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			SqlParameter[] parameters = {
					new SqlParameter("@tblName", SqlDbType.VarChar, 255),
					new SqlParameter("@fldName", SqlDbType.VarChar, 255),
					new SqlParameter("@PageSize", SqlDbType.Int),
					new SqlParameter("@PageIndex", SqlDbType.Int),
					new SqlParameter("@IsReCount", SqlDbType.Bit),
					new SqlParameter("@OrderType", SqlDbType.Bit),
					new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
					};
			parameters[0].Value = "majors";
			parameters[1].Value = "majors_id";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  Method
	}
}

